package quotation.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author lyx
 * @date 2025/2/24
 */
@Getter
@AllArgsConstructor
public enum TimeUnitEnum {

    day(1, TimeUnit.DAYS),
    hour(2, TimeUnit.HOURS),
    min(3, TimeUnit.MINUTES);


    private Integer code;

    private TimeUnit timeUnit;

    private static final Map<Integer, TimeUnitEnum> CODE_TO_ENUM_MAP = new HashMap<>();

    static {
        for (TimeUnitEnum timeUnitEnum : TimeUnitEnum.values()) {
            CODE_TO_ENUM_MAP.put(timeUnitEnum.getCode(), timeUnitEnum);
        }
    }


    public static TimeUnitEnum fromCode(Integer code) {
        return CODE_TO_ENUM_MAP.get(code);
    }
}
